#include "typedef.h"
#include "os_sys.h"
#include "os_tick.h"
#include "beep_driver.h"

#include "beep_bsp.h"


#define BEEP_TASK_TICK (2000)

struct BEEP_TASK_S
{
	SysTick_t beep_tick;

};

struct BEEP_TASK_S beep_task={.beep_tick=0};


/***********************************************************************/
u32 beep_test=0;
static void beep_run(void)
{
	if (0 == systick_get_difference_assign(&beep_task.beep_tick, BEEP_TASK_TICK))
        return;
	switch(beep_test)
	{
		case 0x01:
			beep_on_level(Tnms(500));
		break;
		case 0x02:
			beep_on(1000,Tnms(500));
		break;

	}
	beep_test=0;

}

static void beep_main_run(void)
{
	switch(sys_task_state_get(TASKID_BEEP ))
	{
		case TASK_STAT_FREE:
		case TASK_STAT_POWER_ON:
		case TASK_STAT_INITIAL:
			sys_task_state_set(TASKID_BEEP,TASK_STAT_RUN);
		break;
		case TASK_STAT_RUN:
			beep_run();
		break;
		case TASK_STAT_UNINITIAL:
			sys_task_state_set(TASKID_BEEP,TASK_STAT_POWER_OFF);
		break;
		case TASK_STAT_POWER_OFF:
		case TASK_STAT_SLEEP:

		break;
		default:
			sys_task_state_set(TASKID_BEEP,TASK_STAT_POWER_OFF);
		break;
	}
}
static void beep_peripheral_sleep(void)
{}


static void beep_message_process(E_DATAID DatID, const u32 data)
{
	switch(DatID)
	{
		default:break;
	}
}

static void beep_variable_init(void)
{
    beep_bsp_init();

}

//CONSTRUCTOR_DEFAUTL()
void beep_task_ceate(void)
{
	struct task_s task = TASK_DEFAULT_INIT();

	task.ID 		= TASKID_BEEP;
	task.state		= TASK_STAT_FREE;
	task.TaskTime	= 0;
	task.run 		= beep_main_run;
	task.sleep_init = beep_peripheral_sleep;
	task.msg_process= beep_message_process;
	task.task_tick 	= NULL;
	task.is_used 	= 1;
	task.task_init 	= beep_variable_init;
	sys_task_add(&task);
}

